﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace InSys.Documents
{
    public partial class FormReportAddedDocumentsByPeriod : Form
    {
        private MapTestLinqDataContext db;
        private string kindDocument;
        private int id_user;
        string userName;
        private AccessUserLoginInfo userInfo;

        public FormReportAddedDocumentsByPeriod()
        {
            InitializeComponent();
            db = new MapTestLinqDataContext();
            id_user = -1;
            userName = "";
            userInfo = new AccessUserLoginInfo();
        }

        public FormReportAddedDocumentsByPeriod(int id_user)
            : this()
        {
            this.id_user = id_user;
        }

        private void FormReportAddedDocumentsByPeriod_Load(object sender, EventArgs e)
        {
            kindDocument = (from item in db.kindDocument where item.id == Program.gKindDocument select item.kind_document).FirstOrDefault();
            labelKindDoc.Text = string.Format("Вид документа: {0}", kindDocument);
            userName = userInfo.GetUserNameById(id_user);
            this.reportViewer1.RefreshReport();
        }

        private void buttonExec_Click(object sender, EventArgs e)
        {
            DataTableCountAddedDocumentsTableAdapter.Fill(testlinqDataSet.DataTableCountAddedDocuments, Program.gKindDocument, dateTimePickerStart.Value, dateTimePickerStop.Value);
            ReportParameter rpKindDocument = new ReportParameter("ReportParameterKindDocument", kindDocument);
            ReportParameter rpUserName = new ReportParameter("ReportParameterUser", userName);
            ReportParameter rpDateStart = new ReportParameter("ReportParameterDateStart", dateTimePickerStart.Value.ToString());
            ReportParameter rpDateStop = new ReportParameter("ReportParameterDateStop", dateTimePickerStop.Value.ToString());
            reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rpKindDocument, rpUserName, rpDateStart, rpDateStop });
            reportViewer1.RefreshReport();
        }
    }
}
